/*
 * Handler(=Timer task) for redraw.
 */
package com.hackathon;

import android.os.Handler;
import android.os.Message;
import android.view.View;

public class RedrawHandler extends Handler {
    
	private View view;
    private int delayTime;
    private int frameRate;
    
    public RedrawHandler(View view, int frameRate) {
        this.view = view;
        this.frameRate = frameRate;
    }
    public void start() {
        this.delayTime = 1000 / frameRate;
        this.sendMessageDelayed(obtainMessage(0), delayTime);
    }
    public void stop() {
        delayTime = 0;
    }
    @Override
    public void handleMessage(Message msg) {
        view.invalidate();
        if (delayTime == 0) return; // stop
        sendMessageDelayed(obtainMessage(0), delayTime);
    }
}